package com.naza.rpc.register;

import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.pojo.Instance;
import com.ecwid.consul.v1.ConsulClient;
import com.naza.rpc.client.ConsClient;
import com.naza.rpc.client.NacosClient;
import com.naza.rpc.model.ServiceInstance;
import com.naza.rpc.parallel.policy.BlockingPolicy;
import com.naza.rpc.util.InstanceUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ConsulRegister implements Registry {

    private static final Logger LOG = LoggerFactory.getLogger(ConsulRegister.class);

    ConsClient client = ConsClient.getINSTANCE();

    @Override
    public void register(ServiceInstance serviceInstance) {
        try {
            client.registerInstance(serviceInstance.getServiceName(),serviceInstance);
        } catch (Exception e) {
            LOG.error("Error in register service to consul.",e);
        }
    }

    @Override
    public void deRegister(ServiceInstance serviceInstance) {
        try {
            client.deRegisterInstance(serviceInstance.getServiceName(),serviceInstance);
        } catch (Exception e) {
            LOG.error("Error in deRegister service to consul.",e);
        }
    }
}
